<?php

/**
{price [cents=2] [delim=.]}XXX.YY{/price}
*/

function show_price($params, $content, &$smarty, &$repeat)
{
   if (isset($content)) 
   {
		$cents = 0;
		if (array_key_exists('cents',$params)) {
			$cents = (int)$params['cents'];
		}
		
		$delim = '.';
		if (array_key_exists('delim',$params)) {
			$delim = (string)$params['delim'];
		}
		
		$parts = array();
		preg_match("/^(\d*)\.(\d*)$/", trim($content), $parts);
		if (count($parts) == 3) 
		{
			return $parts[1] . ($cents>0 ? ($delim . substr($parts[2],0,$cents)) : '');
		}
		
		return $content;
   }
}

$smarty->register_block("price", "show_price");

?>